<script>
import QSGDrawer from "@/components/QSGDrawer/index.vue";

export default {
  name: "RenameDialog",
  components: {QSGDrawer},
  data() {
    return {
      dialogVisible: false,
      loading: false,
      ruleForm: {
        id: '',
        name: ''
      },
      rules: {
        name: [
          {required: true, message: '请输入名称', trigger: 'blur'},
          {min: 0, max: 10, message: '长度在 0 到 10 个字符', trigger: 'blur'}
        ],
        fileUrl: [
          {required: true, message: '请输入路径', trigger: 'blur'},
        ]
      }
    }
  },
  methods: {
    close() {
      this.dialogVisible = false
    },
    open(data) {
      console.log(data);
      this.dialogVisible = true
      this.loading = false
      this.ruleForm = {...data}
      this.ruleForm.id = data.id
      this.$nextTick(() => {
        this.$refs.ruleForm.clearValidate()
      })
    },
    submitData() {
      this.loading = true
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.$emit('on-submit', this.ruleForm)
        } else {
          console.log('error submit!!');
          this.loading = false
          return false;
        }
      });
    }
  }
}
</script>

<template>
  <q-s-g-drawer
    ref="drawer"
    :visible.sync="dialogVisible"
    size="600px"
    title="编辑"
  >
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto">
      <el-form-item label="资源包名称" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="资源包路径" prop="fileUrl">
        <el-input v-model="ruleForm.fileUrl" :disabled="ruleForm.type === 3"></el-input>
      </el-form-item>
      <el-form-item label="类型" prop="fileUrl">
        <el-input :value="ruleForm.type === 3 ?'Web3D': 'UE3D'" disabled></el-input>
      </el-form-item>
      <el-form-item label="资源包ID" prop="id">
        <el-input v-model="ruleForm.id" disabled></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="">
        <el-switch
          v-model="ruleForm.status"
          :inactive-value="1"
          inactive-text="停用"
          active-text="启用"
          :active-value="0"
          disabled
        >
        </el-switch>
      </el-form-item>
      <el-form-item label="创建时间" prop="">
        <el-input v-model="ruleForm.createTime" disabled></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button
        type="primary"
        icon="el-icon-circle-plus-outline"
        size="small"
        :loading="loading"
        @click="submitData"
      >保 存
      </el-button>
      <el-button
        type="default"
        icon="el-icon-circle-close"
        size="small"
        :loading="loading"
        @click="dialogVisible = false"
      >
        取消
      </el-button>
    </template>

  </q-s-g-drawer>
</template>

<style scoped lang="scss">

</style>
